package org.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.app.entity.Notice;
import org.app.mapper.NoticeMapper;
import org.app.service.NoticeService;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    
    @Override
    public Notice getLatestNotice() {
        LambdaQueryWrapper<Notice> queryWrapper = new LambdaQueryWrapper<>();
        // 只查询已发布的公告
        queryWrapper.eq(Notice::getStatus, 1);
        
        // 优先查询置顶的公告，再按创建时间倒序
        queryWrapper.orderByDesc(Notice::getIsTop)
                    .orderByDesc(Notice::getCreateTime);
        
        // 限制只返回一条
        queryWrapper.last("LIMIT 1");
        
        return getOne(queryWrapper);
    }
} 